import sys
from PyQt5.QtWidgets import QApplication, QMainWindow
from PyQt5 import QtCore, QtGui, QtWidgets

import UI
from functools import partial


def exchange_rate_US_to_RMB(ui):
    # 获取文本框数据
    input = ui.textEdit.toPlainText()
    result = float(input) * 6.7
    # 设置文本框数据
    ui.textEdit_2.setText(str(result))


def exchange_rate_RMB_to_US(ui):
    # 获取文本框数据
    input = ui.textEdit_2.toPlainText()
    result = float(input) / 6.7
    # 设置文本框数据
    ui.textEdit.setText(str(result))

def fahrenheit_to_celsius(ui):
    fahrenheit_degrees = ui.textEdit_6.toPlainText()
    celsius_degrees = (float(fahrenheit_degrees)-32)/1.8
    ui.textEdit_5.setText(str(celsius_degrees))

def celsius_to_fahrenheit(ui):
    celsius_degrees= ui.textEdit_5.toPlainText()
    fahrenheit_degrees = float(celsius_degrees)*1.8+32
    ui.textEdit_6.setText(str(fahrenheit_degrees))

if __name__ == '__main__':
    app = QApplication(sys.argv)
    MainWindow = QMainWindow()
    ui = UI.Ui_MainWindow()
    ui.setupUi(MainWindow)
    MainWindow.show()
    # 向槽（函数）传入参数
    er = partial(exchange_rate_US_to_RMB, ui)
    ui.btn_us_rmb.clicked.connect(er)
    ui.btn_rmb_us.clicked.connect(partial(exchange_rate_RMB_to_US, ui))
    ui.c_to_f.clicked.connect(partial(celsius_to_fahrenheit, ui))
    ui.f_to_c.clicked.connect(partial(fahrenheit_to_celsius, ui))
    sys.exit(app.exec_())
